cart = []
coupon = ["海尔洗衣机",
          "联想Thinkpad E580",
          "Mac 电脑",
          "Iphone 15 Pro max",
          "海尔冰箱",
          "雅诗兰黛 化妆品",
          "橘子",
          "泰国金枕榴莲",
          "卫龙辣条",
          "康师傅 麻辣方便面",
          ]
goods = [
    ["海尔洗衣机", 2500],
    ["联想Thinkpad E580", 4500],
    ["Mac 电脑", 12000],
    ["Iphone 15 Pro max", 8000],
    ["海尔冰箱", 1200],
    ["雅诗兰黛 化妆品", 200],
    ["橘子", 10],
    ["泰国金枕榴莲", 45],
    ["卫龙辣条", 5],
    ["康师傅 麻辣方便面", 12.5]
]
import random
import time
ran = random.randint(0, 9)
couponame = coupon[ran]
print('您抽中的优惠券是', couponame)
total = 0
money = input("请输入您的余额:")
money = int(money)
while True:
    #    print('购物界面'.center(100,"*"))
    for index, value in enumerate(goods):  # enumerate()枚举将所有商品和编号单独分离开显示
        print(index, value)
    choose = input('请选择商品序号')
    # quan = int(input('请输入您要购买的数量'))
    if choose == "q" or choose == "Q":
        money = money - total
        print("欢迎下次光临！ByeBye!")
        break
    elif choose.isdigit():  # "56" --> 56   "a" -->  False
        choose = int(choose)
        if choose >= len(goods):
            print("对不起，没这个商品！")
        elif choose == ran:
            nub = (int(goods[choose][1]))*0.8
            total = total + nub
            if total <= money:
                cart.append(choose)
                print('添加成功！目前总金额为：', total, '元')
            else:
                print("对不起，钱不够，穷鬼！请到其他地方购买！")
                total = total - nub
                print('添加成功！目前总金额为：', total, '元')
        else:
            nub = int(goods[choose][1])
            total = total + nub
            if total <= money:
                cart.append(choose)
                print('添加成功！目前总金额为：', total, '元')
            else:
                print("对不起，钱不够，穷鬼！请到其他地方购买！")
                total = total - nub
                print('添加成功！目前总金额为：', total, '元')

    else:
        print('请输入正确商品编号')
#  商品去重
test = []
for i in cart:
    if i not in test:
        test.append(i)

# 打印购物小条
print("------------------这是您的购物小条，请拿好--------------------")
print("--------------------Jason商城----------------------------")
for i in test:
    if i == ran:
        print(f"商品名：{goods[i][0]}, 数量：{cart.count(i)}, 单价(折后)：{(goods[i][1])*0.8}, 总金额（折后）：{((cart.count(i)) * (goods[i][1]))*0.8}")
    else:
        print(f"商品名：{goods[i][0]}, 数量：{cart.count(i)}, 单价：{goods[i][1]}, 总金额：{(cart.count(i))*(goods[i][1])}")
print("-----------------------------------------")
print("您消费的总金额为", total)
print("您的卡余额还剩：￥", money)
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
